home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 3 / ct-rom iiib.zip / ct-rom iiib / WINDOWS / DIVERSEN / WINE02BX / ELISP.12 < prev    next >
Text File  |  1993-03-28  |  51KB  |  1,184 lines

  1. Info file elisp, produced by Makeinfo, -*- Text -*- from input file
  2. elisp.texi.
  3.  
  4.    This file documents GNU Emacs Lisp.
  5.  
  6.    This is edition 1.03 of the GNU Emacs Lisp Reference Manual,   for
  7. Emacs Version 18.
  8.  
  9.    Published by the Free Software Foundation, 675 Massachusetts
  10. Avenue,  Cambridge, MA 02139 USA
  11.  
  12.    Copyright (C) 1990 Free Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of
  15. this manual provided the copyright notice and this permission notice
  16. are preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Foundation.
  27.  
  28.  
  29. 
  30. File: elisp,  Node: Key Lookup,  Next: Functions for Key Lookup,  Prev: Creating Keymaps,  Up: Keymaps
  31.  
  32. Key Lookup
  33. ==========
  34.  
  35.    "Key lookup" is the process of finding the binding of a key
  36. sequence from a given keymap.  Actual execution of the definition is
  37. not part of key lookup.
  38.  
  39.    When the key sequence consists of multiple characters, the
  40. characters are handled sequentially: the binding of the first
  41. character is found, and must be a keymap; then the second character's
  42. binding is found in that keymap, and so on until all the characters
  43. in the key sequence are used up.  (The binding thus found for the
  44. last character may or may not be a keymap.)  Thus, the process of key
  45. lookup is defined in terms of a simpler process for looking up a
  46. single character in a keymap.  How this is done depends on the type
  47. of object associated with the character in that keymap.
  48.  
  49.    The value directly associated with a character in a keymap is
  50. called a "keymap entry".  While any Lisp object may be stored in a
  51. keymap entry, only a few types of object make sense for key lookup. 
  52. Here is a list of them, and what they mean:
  53.  
  54. `nil'
  55.      `nil' means that the characters used so far in the lookup form
  56.      an undefined key.  When a sparse keymap fails to mention a
  57.      character, that is equivalent to an entry of `nil'.
  58.  
  59. KEYMAP
  60.      The characters used so far in the lookup form a prefix key.  The
  61.      next character of the key sequence is looked up in KEYMAP, which
  62.      may be full or sparse.
  63.  
  64. COMMAND
  65.      The characters used so far in the lookup form a complete key,
  66.      and COMMAND is its definition.
  67.  
  68. STRING
  69.      STRING represents a keyboard macro.  The characters used so far
  70.      in the lookup form a complete key, and STRING is its definition.
  71.      (See *Note Keyboard Macros::, for more information.)
  72.  
  73. LIST
  74.      The meaning of a list depends on the types of the elements of
  75.      the list.
  76.  
  77.         * If the CAR of LIST is the symbol `keymap', then the list is
  78.           a sparse keymap, and is treated as a keymap (see above).
  79.  
  80.         * If the CAR of LIST is `lambda', then the list is a lambda
  81.           expression.  This is presumed to be a command, and is
  82.           treated as such (see above).
  83.  
  84.         * If the CAR of LIST is a keymap and the CDR is a character,
  85.           then this entry is an indirection to a slot in the other
  86.           keymap.  When an indirect entry is found in key lookup, it
  87.           is immediately replaced by the entry in the specified
  88.           keymap for the specified character.  This permits you to
  89.           define one key as an alias for another key.  For example,
  90.           an entry whose CAR is the keymap called `esc-map' and whose
  91.           CDR is 32 (the code for space) means, "Use the global
  92.           definition of `Meta-SPC', whatever that may be."
  93.  
  94. SYMBOL
  95.      The function definition of SYMBOL is used in place of SYMBOL. 
  96.      If that too is a symbol, then this process is repeated, any
  97.      number of times.  Ultimately this should lead to a definition
  98.      which is a keymap, a command or a string.  A list is allowed if
  99.      it is a keymap or a command, but indirect entries are not
  100.      understood when found via symbols.
  101.  
  102.      Note that keymaps and strings are not valid functions, so a
  103.      symbol with a keymap or string as its function definition is
  104.      likewise not valid as a function.  It is, however, valid as a
  105.      key binding.  If the definition is a string, then the symbol is
  106.      also valid as an argument to `command-execute' (*note
  107.      Interactive Call::.).
  108.  
  109.      The symbol `undefined' is worth special mention: it means to
  110.      treat the key as undefined.  Strictly speaking, the key is
  111.      defined, and its definition is the symbol `undefined', but that
  112.      command does the same thing that is done automatically for an
  113.      undefined key: it rings the bell (by calling `ding') but does
  114.      not signal an error.
  115.  
  116.      `undefined' is used in local keymaps to override a global key
  117.      binding and make the key undefined locally.  A local binding of
  118.      `nil' would fail to do this because it would not override the
  119.      global binding.
  120.  
  121. ANYTHING ELSE
  122.      If any other type of object is found, the characters used so far
  123.      in the lookup form a complete key, and the object is its
  124.      definition.
  125.  
  126.    In short, a keymap entry may be a keymap, a command, a string, a
  127. symbol which leads to one of them, or an indirection or `nil'.  Here
  128. is an example of a sparse keymap with two characters bound to
  129. commands and one bound to another keymap.  This map is the normal
  130. value of `emacs-lisp-mode-map'.  Note that 9 is the code for TAB, 127
  131. for DEL, 27 for ESC, 17 for `C-q' and 24 for `C-x'.
  132.  
  133.      (keymap (9 . lisp-indent-line)
  134.              (127 . backward-delete-char-untabify)
  135.              (27 keymap (17 . indent-sexp) (24 . eval-defun)))
  136.  
  137.  
  138. 
  139. File: elisp,  Node: Functions for Key Lookup,  Next: Prefix Keys,  Prev: Key Lookup,  Up: Keymaps
  140.  
  141. Functions for Key Lookup
  142. ========================
  143.  
  144.    Here are the functions and variables pertaining to key lookup.
  145.  
  146.  * Function: lookup-key KEYMAP KEY
  147.      This function returns the definition of KEY in KEYMAP.  If the
  148.      string KEY is not a valid key sequence according to the prefix
  149.      keys specified in KEYMAP (which means it is "too long" and has
  150.      extra characters at the end), then the value is a number, the
  151.      number of characters at the front of KEY that compose a complete
  152.      key.
  153.  
  154.      All the other functions described in this chapter that look up
  155.      keys use `lookup-key'.
  156.  
  157.           (lookup-key (current-global-map) "\C-x\C-f")
  158.               => find-file
  159.           (lookup-key (current-global-map) "\C-x\C-f12345")
  160.               => 2
  161.  
  162.      If KEY contains a meta-character, that character is implicitly
  163.      replaced by a two-character sequence: the value of
  164.      `meta-prefix-char', followed by the corresponding non-meta
  165.      character.  Thus, the first example below is handled by
  166.      conversion into the second example.
  167.  
  168.           (lookup-key (current-global-map) "\M-f")
  169.               => forward-word
  170.           (lookup-key (current-global-map) "\ef")
  171.               => forward-word
  172.  
  173.      This function does not perform automatic downcasing like that of
  174.      `read-key-sequence' (*note Keyboard Input::.).
  175.  
  176.  * Command: undefined
  177.      Used in keymaps to undefine keys.  It calls `ding', but does not
  178.      cause an error.
  179.  
  180.  * Variable: meta-prefix-char
  181.      This variable is the meta-prefix character code.  It is used
  182.      when translating a meta-character to a two-character sequence so
  183.      it can be looked up in a keymap.  For useful results, the value
  184.      should be a prefix character (*note Prefix Keys::.).  The
  185.      default value is 27, which is the ASCII code for ESC.
  186.  
  187.      As long as the value of `meta-prefix-char' remains 27, key
  188.      lookup translates `M-b' into `ESC b', which is normally defined
  189.      as the `backward-word' command.  However, if you set
  190.      `meta-prefix-char' to 24, the code for `C-x', then Emacs will
  191.      translate `M-b' into `C-x b', and call the `switch-to-buffer'
  192.      command.
  193.  
  194.           meta-prefix-char                    ; The default value.
  195.                => 27
  196.           (key-binding "\M-b")
  197.                => backward-word
  198.           ?\C-x                               ; The print representation
  199.                => 24                          ; of a character.
  200.           (setq meta-prefix-char 24)
  201.                => 24      
  202.           (key-binding "\M-b")
  203.                => switch-to-buffer            ; Now, typing `M-b' is
  204.                                               ; like typing `C-x b'.
  205.           
  206.           (setq meta-prefix-char 27)          ; Avoid confusion!
  207.                => 27                          ; Restore the default value!
  208.  
  209.  
  210. 
  211. File: elisp,  Node: Prefix Keys,  Next: Global and Local Keymaps,  Prev: Functions for Key Lookup,  Up: Keymaps
  212.  
  213. Prefix Keys
  214. ===========
  215.  
  216.    A "prefix key" has an associated keymap which defines what to do
  217. with key sequences that start with the prefix key.  For example,
  218. `ctl-x-map' is the keymap used for characters following the prefix
  219. key `C-x'.  Here is a list of the standard prefix keys of Emacs and
  220. their keymaps:
  221.  
  222.    * `ctl-x-map' is the variable name for the map used for characters
  223.      that follow `C-x'.  This map is also the function definition of
  224.      `Control-X-prefix'.
  225.  
  226.    * `ctl-x-4-map' used is for characters that follow `C-x 4'.
  227.  
  228.    * `esc-map' is used for characters that follow ESC.  Thus, the
  229.      global definitions of all Meta characters are actually found
  230.      here.  This map is also the function definition of `ESC-prefix'.
  231.  
  232.    * `help-map' is used for characters that follow `C-h'.
  233.  
  234.    * `mode-specific-map' is for characters that follow `C-c'.  This
  235.      map is not actually mode specific; its name was chosen to be
  236.      informative for the user in `C-h b' (`display-bindings'), where
  237.      it describes the main use of the `C-c' prefix key.
  238.  
  239.    The binding of a prefix key is the keymap to use for looking up
  240. the characters that follow the prefix key.  (It may instead be a
  241. symbol whose function definition is a keymap.  The effect is the
  242. same, but the symbol serves as a name for the prefix key.)  Thus, the
  243. binding of `C-x' is the symbol `Control-X-prefix', whose function
  244. definition is the keymap for `C-x' commands.  This keymap is also the
  245. value of `ctl-x-map'.
  246.  
  247.    Prefix key definitions of this sort can appear in either the
  248. global map or a local map.  The definitions of `C-c', `C-x', `C-h'
  249. and ESC as prefix keys appear in the global map, so these prefix keys
  250. are always available.  Major modes can locally redefine a key as a
  251. prefix by putting a prefix key definition for it in the local map.
  252.  
  253.    If a key is defined as a prefix in both the local map and the
  254. global, the two definitions are effectively merged: the commands
  255. defined in the local map's prefix definition take priority; those not
  256. defined there are taken from the global map.
  257.  
  258.    In the following example, `C-p' is made a prefix key in the local
  259. keymap (so that `C-p' is identical to `C-x').  Then the binding for
  260. `C-p C-f' is the function `find-file', just like `C-x C-f'.  The key
  261. sequence `C-p 6' is not found in either the local map or global map.
  262.  
  263.      (use-local-map (make-sparse-keymap))
  264.          => nil
  265.      (local-set-key "\C-p" ctl-x-map)
  266.          => nil
  267.      (key-binding "\C-p\C-f")
  268.          => find-file
  269.      
  270.      (key-binding "\C-p6")
  271.          => nil
  272.  
  273.  * Function: define-prefix-command SYMBOL
  274.      This function defines SYMBOL as a prefix command: it creates a
  275.      full keymap and stores it as SYMBOL's function definition. 
  276.      Storing the symbol as the binding of a key makes the key a
  277.      prefix key which has a name.  This function returns SYMBOL.
  278.  
  279.      It is convenient to store the keymap as the value of a variable
  280.      as well.  In version 19, this function stores the keymap in both
  281.      the function definition and value of SYMBOL.  However, in
  282.      version 18, only the function definition of SYMBOL is set, not
  283.      the value.
  284.  
  285.  
  286. 
  287. File: elisp,  Node: Global and Local Keymaps,  Next: Changing Key Bindings,  Prev: Prefix Keys,  Up: Keymaps
  288.  
  289. Global and Local Keymaps
  290. ========================
  291.  
  292.    The "global keymap" holds the bindings of keys that are defined
  293. regardless of the current buffer, such as `C-f'.  The variable
  294. `global-map' holds this keymap.
  295.  
  296.    Each buffer may have another keymap, its "local keymap", which may
  297. contain new or overriding definitions for keys.  Each buffer records
  298. which local keymap is used with it.
  299.  
  300.    Both the global and local keymaps are used to determine what
  301. command to execute when a key is entered.  The key lookup proceeds as
  302. described earlier (*note Key Lookup::.), but Emacs *first* searches
  303. for the key in the local map; if Emacs does not find a local
  304. definition, Emacs then searches the global map.
  305.  
  306.    Since every buffer that uses the same major mode normally uses the
  307. very same local keymap, it may appear as if the keymap is local to
  308. the mode.  A change to the local keymap of a buffer (using
  309. `local-set-key', for example) will be seen also in the other buffers
  310. that share that keymap.
  311.  
  312.    The local keymaps that are used for Lisp mode, C mode, and several
  313. other major modes exist even if they have not yet been used.  These
  314. local maps are the values of the variables `lisp-mode-map',
  315. `c-mode-map', and so on.  For most other modes, which are less
  316. frequently used, the local keymap is constructed only when the mode
  317. is used for the first time in a session.
  318.  
  319.    The minibuffer has local keymaps, too; they contain various
  320. completion and exit commands.  *Note Minibuffers::.
  321.  
  322.    *Note Standard Keymaps::, for a list of standard keymaps.
  323.  
  324.  * Variable: global-map
  325.      This variable contains the default global keymap that maps Emacs
  326.      keyboard input to commands.  Normally this keymap is the global
  327.      keymap.  The default global keymap is a full keymap that binds
  328.      `self-insert-command' to all of the printing characters.
  329.  
  330.  * Function: current-global-map
  331.      This function returns the current global keymap.  Normally, this
  332.      is the same as the value of the `global-map'.
  333.  
  334.           (current-global-map)
  335.           => [set-mark-command beginning-of-line ... delete-backward-char]
  336.  
  337.  * Function: current-local-map
  338.      This function returns the current buffer's local keymap, or
  339.      `nil' if it has none.  In the following example, the keymap for
  340.      the `*scratch*' buffer (using Lisp Interaction mode) is a sparse
  341.      keymap in which the entry for ESC, ASCII code 27, is another
  342.      sparse keymap.
  343.  
  344.           (current-local-map)
  345.           => (keymap 
  346.               (10 . eval-print-last-sexp) 
  347.               (9 . lisp-indent-line) 
  348.               (127 . backward-delete-char-untabify) 
  349.               (27 keymap 
  350.                   (24 . eval-defun) 
  351.                   (17 . indent-sexp)))
  352.  
  353.  * Function: use-global-map KEYMAP
  354.      This function makes KEYMAP the new current global keymap.  The
  355.      KEYMAP map must be a full keymap (a vector of length 128).  It
  356.      returns `nil'.
  357.  
  358.      It is very unusual to change the global keymap.
  359.  
  360.  * Function: use-local-map KEYMAP
  361.      This function makes KEYMAP the new current local keymap of the
  362.      current buffer.  If KEYMAP is `nil', then there will be no local
  363.      keymap.  It returns `nil'.  Most major modes use this function.
  364.  
  365.  * Function: key-binding KEY
  366.      This function returns the definition for KEY in the current
  367.      keymaps trying the current buffer's local map and then the
  368.      global map.  The result is `nil' if KEY is undefined in the
  369.      keymaps.
  370.  
  371.      An error is signaled if KEY is not a string.
  372.  
  373.           (key-binding "\C-x\C-f")
  374.               => find-file
  375.  
  376.  * Function: local-key-binding KEY
  377.      This function returns the definition for KEY in the current
  378.      local keymap, or `nil' if it is undefined there.
  379.  
  380.  * Function: global-key-binding KEY
  381.      This function returns the definition for command KEY in the
  382.      current global keymap, or `nil' if it is undefined there.
  383.  
  384.  
  385. 
  386. File: elisp,  Node: Changing Key Bindings,  Next: Key Binding Commands,  Prev: Global and Local Keymaps,  Up: Keymaps
  387.  
  388. Changing Key Bindings
  389. =====================
  390.  
  391.    The way to rebind a key is to change its entry in a keymap.  You
  392. can change the global keymap, so that the change is effective in all
  393. buffers (except those that override the global definition with a
  394. local one).  Or you can change the current buffer's local map, which
  395. usually affects all buffers using the same major mode.  The
  396. `global-set-key' and `local-set-key' functions are convenient
  397. interfaces for these operations.  Or you can change bindings in any
  398. map by specifying it explicitly in `define-key'.
  399.  
  400.    People often use `global-set-key' in their `.emacs' file for
  401. simple customization.  For example,
  402.  
  403.      (global-set-key "\C-x\C-\\" 'next-line)
  404.  
  405. redefines `C-x C-\' to move down a line.
  406.  
  407.    In writing the string for the key sequence to rebind, it is useful
  408. to use the special escape sequences for control and meta characters
  409. (*note String Type::.).  In a string, the syntax `\C-' means that the
  410. following character is a control character and `\M-' means that the
  411. following character is a META character.  Thus, the string `"\M-x"'
  412. is read as containing a single `M-x', `"\C-f"' is read as containing
  413. a single `C-f', and `"\M-\C-x"' and `"\C-\M-x"' are both read as
  414. containing a single `C-M-x'.
  415.  
  416.    For the functions below, an error is signaled if KEYMAP is not a
  417. keymap or if KEY is not a string representing a key sequence.
  418.  
  419.  * Function: define-key KEYMAP KEY DEFINITION
  420.      This function sets the binding for KEY in KEYMAP.  (If KEY is
  421.      more than one character long, the change is actually made in
  422.      another keymap reached from KEYMAP.)  The argument DEFINITION
  423.      can be any Lisp object, but only certain types are meaningful. 
  424.      (For a list of meaningful types, see *Note Key Lookup::.) The
  425.      value returned by `define-key' is DEFINITION.
  426.  
  427.      Every prefix of KEY must be a prefix key (i.e., bound to a
  428.      keymap) or undefined; otherwise an error is signaled (with data
  429.      `(error "Key sequence KEY uses invalid prefix characters")'). 
  430.      If some prefix of KEY is undefined, then `define-key' defines it
  431.      as a prefix key so that the rest of KEY may be defined as
  432.      specified.
  433.  
  434.      In the following example, a sparse keymap is created and a
  435.      number of bindings are added to it.
  436.  
  437.           (setq map (make-sparse-keymap))
  438.               => (keymap)
  439.           (define-key map "\C-f" 'forward-char)
  440.               => forward-char
  441.           map
  442.               => (keymap (6 . forward-char))
  443.  
  444.              ;; Build sparse submap for `C-x' and bind `f' in that.
  445.           (define-key map "\C-xf" 'forward-word)
  446.               => forward-word
  447.  
  448.           map
  449.           => (keymap 
  450.               (24 keymap                ; `C-x'
  451.                   (102 . forward-word)) ;      `f'
  452.               (6 . forward-char))       ; `C-f'
  453.           
  454.           ;; Bind `C-p' to the `ctl-x-map'.
  455.           (define-key map "\C-p" ctl-x-map)
  456.           => [nil ...  find-file ... backward-kill-sentence] ; `ctl-x-map'
  457.           
  458.           ;; Bind `C-f' to `foo' in the `ctl-x-map'.
  459.           (define-key map "\C-p\C-f" 'foo)
  460.           => 'foo
  461.           map
  462.           => (keymap     ; Note `foo' in `ctl-x-map'.
  463.               (16 . [nil ...  foo ... backward-kill-sentence])
  464.               (24 keymap 
  465.                   (102 . forward-word))
  466.               (6 . forward-char))
  467.  
  468.      Note that storing a new binding for `C-p C-f' actually works by
  469.      changing an entry in `ctl-x-map', and this has the effect of
  470.      changing the bindings of both `C-p C-f' and `C-x C-f' in the
  471.      default global map.
  472.  
  473.  * Function: substitute-key-definition OLDDEF NEWDEF KEYMAP
  474.      This function replaces OLDDEF with NEWDEF for any keys in KEYMAP
  475.      that were bound to OLDDEF.  In other words, OLDDEF is replaced
  476.      with NEWDEF wherever it appears.  It returns `nil'.
  477.  
  478.      Prefix keymaps that appear within KEYMAP are not checked
  479.      recursively for keys bound to OLDDEF; they are not changed at all.
  480.      Perhaps it would be better to check nested keymaps recursively.
  481.  
  482.           (setq map '(keymap 
  483.                       (?1 . olddef-1) 
  484.                       (?2 . olddef-2) 
  485.                       (?3 . olddef-1)))
  486.           => (keymap (49 . olddef-1) (50 . olddef-2) (51 . olddef-1))
  487.           
  488.           (substitute-key-definition 'olddef-1 'newdef map)
  489.           => nil
  490.           map
  491.           => (keymap (49 . newdef) (50 . olddef-2) (51 . newdef))
  492.           
  493.           ;; The following will redefine `C-x C-f', if you do it in an
  494.           ;; Emacs with standard bindings.
  495.           
  496.           (substitute-key-definition 
  497.            'find-file 'find-file-read-only (current-global-map))
  498.  
  499.  * Function: suppress-keymap KEYMAP &optional NODIGITS
  500.      This function changes the contents of the full keymap KEYMAP by
  501.      replacing the self-insertion commands for numbers with the
  502.      `digit-argument' function, unless NODIGITS is non-`nil', and by
  503.      replacing the functions for the rest of the printing characters
  504.      with `undefined'.  This means that ordinary insertion of text is
  505.      impossible in a buffer with a local keymap on which
  506.      `suppress-keymap' has been called.
  507.  
  508.      `suppress-keymap' returns `nil'.
  509.  
  510.      The `suppress-keymap' function does not make it impossible to
  511.      modify a buffer, as it does not suppress commands such as `yank'
  512.      and `quote-insert'.  To prevent any modification of a buffer,
  513.      make it read-only (*note Read Only Buffers::.).
  514.  
  515.      Since this function modifies KEYMAP, you would normally use it
  516.      on a newly created keymap.  Operating on an existing keymap that
  517.      is used for some other purpose is likely to cause trouble; for
  518.      example, suppressing `global-map' would make it impossible to
  519.      use most of Emacs.
  520.  
  521.      Most often, `suppress-keymap' is used for initializing local
  522.      keymaps of modes such as Rmail and Dired where insertion of text
  523.      is not desirable and the buffer is read-only.  Here is an
  524.      example taken from the file `emacs/lisp/dired.el', showing how
  525.      the local keymap for Dired mode is set up:
  526.  
  527.             ...
  528.             (setq dired-mode-map (make-keymap))
  529.             (suppress-keymap dired-mode-map)
  530.             (define-key dired-mode-map "r" 'dired-rename-file)
  531.             (define-key dired-mode-map "\C-d" 'dired-flag-file-deleted)
  532.             (define-key dired-mode-map "d" 'dired-flag-file-deleted)
  533.             (define-key dired-mode-map "v" 'dired-view-file)
  534.             (define-key dired-mode-map "e" 'dired-find-file)
  535.             (define-key dired-mode-map "f" 'dired-find-file)
  536.             ...
  537.  
  538.  
  539. 
  540. File: elisp,  Node: Key Binding Commands,  Next: Scanning Keymaps,  Prev: Changing Key Bindings,  Up: Keymaps
  541.  
  542. Commands for Binding Keys
  543. =========================
  544.  
  545.    This section describes some convenient interactive interfaces for
  546. changing key bindings.  They work by calling `define-key'.
  547.  
  548.  * Command: global-set-key KEY DEFINITION
  549.      This function sets the binding of KEY in the current global map
  550.      to DEFINITION.
  551.  
  552.           (global-set-key KEY DEFINITION)
  553.           ==
  554.           (define-key (current-global-map) KEY DEFINITION)
  555.  
  556.  * Command: global-unset-key KEY
  557.      This function removes the binding of KEY from the current global
  558.      map.
  559.  
  560.      One use of this function is in preparation for defining a longer
  561.      key which uses it implicitly as a prefix--which would not be
  562.      allowed otherwise.  For example:
  563.  
  564.           (global-unset-key "\C-l")
  565.               => nil
  566.           (global-set-key "\C-l\C-l" 'redraw-display)
  567.               => nil
  568.  
  569.      This function is implemented simply using `define-key':
  570.  
  571.           (global-unset-key KEY)
  572.           ==
  573.           (define-key (current-global-map) KEY nil)
  574.  
  575.  * Command: local-set-key KEY DEFINITION
  576.      This function sets the binding of KEY in the current local
  577.      keymap to DEFINITION.
  578.  
  579.           (local-set-key KEY DEFINITION)
  580.           ==
  581.           (define-key (current-local-map) KEY DEFINITION)
  582.  
  583.  * Command: local-unset-key KEY
  584.      This function removes the binding of KEY from the current local
  585.      map.
  586.  
  587.           (local-unset-key KEY)
  588.           ==
  589.           (define-key (current-local-map) KEY nil)
  590.  
  591.  
  592. 
  593. File: elisp,  Node: Scanning Keymaps,  Prev: Key Binding Commands,  Up: Keymaps
  594.  
  595. Scanning Keymaps
  596. ================
  597.  
  598.    This section describes functions used to scan all the current
  599. keymaps for the sake of printing help information.
  600.  
  601.  * Function: accessible-keymaps KEYMAP
  602.      This function returns a list of all the keymaps that can be
  603.      accessed (via prefix keys) from KEYMAP.  The list returned is an
  604.      association list with elements of the form `(KEY . MAP)', where
  605.      KEY is a prefix whose definition in KEYMAP is MAP.
  606.  
  607.      The elements of the alist are ordered so that the KEY increases
  608.      in length.  The first element is always `("" . KEYMAP)', because
  609.      the specified keymap is accessible from itself with a prefix of
  610.      no characters.
  611.  
  612.      In the example below, the returned alist indicates that the key
  613.      ESC, which is displayed as `"^["', is a prefix key whose
  614.      definition is the sparse keymap `(keymap (83 . center-paragraph)
  615.      (115 . foo))'.
  616.  
  617.           (accessible-keymaps (current-local-map))
  618.           =>(("" keymap 
  619.                 (27 keymap   ; Note this keymap for ESC is repeated below.
  620.                     (83 . center-paragraph)
  621.                     (115 . center-line))
  622.                 (9 . tab-to-tab-stop))
  623.           
  624.              ("^[" keymap 
  625.               (83 . center-paragraph) 
  626.               (115 . foo)))
  627.  
  628.      In the following example, `C-h' is a prefix key that uses a
  629.      sparse keymap starting `(118 . describe-variable) ...'.  Another
  630.      prefix, `C-x 4', uses the full keymap beginning `[nil ...]'
  631.      (which happens to be `ctl-x-4-map').
  632.  
  633.           (accessible-keymaps (current-global-map))
  634.           => (("" . [set-mark-command beginning-of-line ... 
  635.                         delete-backward-char])
  636.               ("^C" keymap (13 . x-flush-mouse-queue))
  637.               ("^H" keymap (118 . describe-variable) ... (8 . help-for-help))
  638.               ("^X" . [x-flush-mouse-queue  ... backward-kill-sentence])
  639.               ("^[" . [mark-sexp backward-sexp ... backward-kill-word])
  640.               ("^X4" . [nil ... find-file-other-window nil ... nil nil]))
  641.  
  642.  * Function: where-is-internal COMMAND &optional KEYMAP FIRSTONLY
  643.      This function returns a list of key sequences (of any length)
  644.      that are bound to COMMAND in KEYMAP and the global keymap.  The
  645.      argument COMMAND can be any object; it is compared with all
  646.      keymap entries using `eq'.  If KEYMAP is not supplied, then the
  647.      global map alone is used.
  648.  
  649.      If FIRSTONLY is non-`nil', then the value is a single string
  650.      representing the first key sequence found, rather than a list of
  651.      all possible key sequences.
  652.  
  653.      This function is used by `where-is' (*note : (emacs)Help.).
  654.  
  655.           (where-is-internal 'describe-function)
  656.               => ("\^hf" "\^hd")
  657.  
  658.  * Command: describe-bindings
  659.      This function creates a listing of all defined keys, and their
  660.      definitions.  The listing is put in a buffer named `*Help*',
  661.      which is then displayed in a window.
  662.  
  663.      A meta character is shown as ESC followed by the corresponding
  664.      non-meta character.  Control characters are indicated with `C-'.
  665.  
  666.      When several consecutive characters have the same definition,
  667.      they are shown together, as `FIRSTCHAR..LASTCHAR'.  In this
  668.      instance, you need to know the ASCII codes to understand which
  669.      characters this means.  For example, in the default global map,
  670.      the characters `SPC .. ~' are described by a single line.  SPC
  671.      is ASCII 32, `~' is ASCII 126, and the characters between them
  672.      include all the normal printing characters, (e.g., letters,
  673.      digits, punctuation, etc.); all these characters are bound to
  674.      `self-insert-command'.
  675.  
  676.  
  677. 
  678. File: elisp,  Node: Modes,  Next: Documentation,  Prev: Keymaps,  Up: Top
  679.  
  680. Major and Minor Modes
  681. *********************
  682.  
  683.    A "mode" is a set of definitions that customize Emacs and can be
  684. turned on and off while you edit.  There are two varieties of modes:
  685. "major modes", which are mutually exclusive and used for editing
  686. particular kinds of text, and "minor modes", which provide features
  687. that may be enabled individually.
  688.  
  689.    This chapter covers both major and minor modes, the way they are
  690. indicated in the mode line, and how they run hooks supplied by the
  691. user.  Related topics such as keymaps and syntax tables are covered
  692. in separate chapters.  (*Note Keymaps::, and *Note Syntax Tables::.)
  693.  
  694. * Menu:
  695.  
  696. * Major Modes::        Defining major modes.
  697. * Minor Modes::        Defining minor modes.
  698. * Mode Line Format::   Customizing the text that appears in the mode line.
  699. * Hooks::              How to use hooks; how to write code that provides hooks.
  700.  
  701.  
  702. 
  703. File: elisp,  Node: Major Modes,  Next: Minor Modes,  Prev: Modes,  Up: Modes
  704.  
  705. Major Modes
  706. ===========
  707.  
  708.    Major modes specialize Emacs for editing particular kinds of text.
  709. Each buffer has only one major mode at a time.
  710.  
  711.    The least specialized major mode is called "Fundamental mode". 
  712. This mode has no mode-specific definitions or variable settings, so
  713. each Emacs command behaves in its default manner, and each option is
  714. in its default state.  All other major modes redefine various keys
  715. and options.  For example, Lisp Interaction mode provides special key
  716. bindings for LFD (`eval-print-last-sexp'), TAB (`lisp-indent-line'),
  717. and other keys.
  718.  
  719.    When you need to write several editing commands to help you
  720. perform a specialized editing task, creating a new major mode is
  721. usually a good idea.  In practice, writing a major mode is easy (in
  722. sharp contrast to writing a minor mode, which is often difficult).
  723.  
  724.    If the new mode is similar to an old one, it is often unwise to
  725. modify the old one to serve two purposes, since it may become harder
  726. to use and maintain.  Instead, copy and rename an existing major mode
  727. definition and alter it for its new function.  For example, Rmail
  728. Edit mode, which is in `emacs/lisp/rmailedit.el', is a major mode
  729. that is very similar to Text mode except that it provides three
  730. additional commands.  Its definition is distinct from that of Text
  731. mode, but was derived from it.
  732.  
  733.    Rmail Edit mode is an example of a case where one piece of text is
  734. put temporarily into a different major mode so it can be edited in a
  735. different way (with ordinary Emacs commands rather than Rmail).  In
  736. such cases, the temporary major mode usually has a command to switch
  737. back to the buffer's usual mode (Rmail mode, in this case).  You
  738. might be tempted to present the temporary redefinitions inside a
  739. recursive edit and restore the usual ones when the user exits; but
  740. this is a bad idea because it constrains the user's options when it
  741. is done in more than one buffer: recursive edits must be exited
  742. most-recently-entered first.  Using alternative major modes avoids
  743. this limitation.  *Note Recursive Editing::.
  744.  
  745.    The standard GNU Emacs Lisp library directory contains the code
  746. for several major modes, in files including `text-mode.el',
  747. `texinfo.el', `lisp-mode.el', `c-mode.el', and `rmail.el'.  You can
  748. look at these libraries to see how modes are written.  Text mode is
  749. perhaps the simplest major mode aside from Fundamental mode.  Rmail
  750. mode is a rather complicated, full-featured mode.
  751.  
  752. * Menu:
  753.  
  754. * Major Mode Conventions::  Coding conventions for keymaps, etc.
  755. * Example Major Modes::     Text mode and Lisp modes.
  756. * Auto Major Mode::         How Emacs chooses the major mode automatically.
  757. * Mode Help::               Finding out how to use a mode.
  758.  
  759.  
  760. 
  761. File: elisp,  Node: Major Mode Conventions,  Next: Example Major Modes,  Prev: Major Modes,  Up: Major Modes
  762.  
  763. Major Mode Conventions
  764. ----------------------
  765.  
  766.    The code for existing major modes follows various coding
  767. conventions, including conventions for local keymap and syntax table
  768. initialization, global names, and hooks.  Please keep these
  769. conventions in mind when you create a new major mode:
  770.  
  771.    * Define a command whose name ends in `-mode', with no arguments,
  772.      that switches to the new mode in the current buffer.  This
  773.      command should set up the keymap, syntax table, and local
  774.      variables in an existing buffer without changing the buffer's
  775.      text.
  776.  
  777.    * Write a documentation string for this command which describes
  778.      the special commands available in this mode.  `C-h m'
  779.      (`describe-mode') will print this.
  780.  
  781.      The documentation string may include the special documentation
  782.      substrings, `\[COMMAND]', `\{KEYMAP}', and `\<KEYMAP>', that
  783.      enable the documentation to adapt automatically to the user's
  784.      own key bindings.  The `describe-mode' function replaces these
  785.      special documentation substrings with their current meanings. 
  786.      *Note Accessing Documentation::.
  787.  
  788.    * The major mode command should set the variable `major-mode' to
  789.      the major mode command symbol.  This is how `describe-mode'
  790.      discovers which documentation to print.
  791.  
  792.    * The major mode command should set the variable `mode-name' to
  793.      the "pretty" name of the mode, as a string.  This appears in the
  794.      mode line.
  795.  
  796.    * Since all global names are in the same name space, all the
  797.      global variables, constants, and functions that are part of the
  798.      mode should have names that start with the major mode name (or
  799.      with an abbreviation of it if the name is long).
  800.  
  801.    * The major mode should usually have its own keymap, which is used
  802.      as the local keymap in all buffers in that mode.  The major mode
  803.      function should call `use-local-map' to install this local map. 
  804.      *Note Global and Local Keymaps::, for more information.
  805.  
  806.      This keymap should be kept in a global variable named
  807.      `MODENAME-mode-map'.  This variable is usually set up when the
  808.      library that defines the mode is loaded.  Use `defvar' to set
  809.      the variable, so that it is not reinitialized if it already has
  810.      a value.  (Such reinitialization could discard customizations
  811.      made by the user.)
  812.  
  813.    * The mode may have its own syntax table or may share one with
  814.      other related modes.  If it has its own syntax table, it should
  815.      store this in a variable named `MODENAME-mode-syntax-table'. 
  816.      The reasons for this are the same as for using a keymap
  817.      variable.  *Note Syntax Tables::.
  818.  
  819.    * The mode may have its own abbrev table or may share one with
  820.      other related modes.  If it has its own abbrev table, it should
  821.      store this in a variable named `MODENAME-mode-abbrev-table'. 
  822.      *Note Abbrev Tables::.
  823.  
  824.    * To give a variable a buffer-local binding, use
  825.      `make-local-variable' in the major mode command, not
  826.      `make-variable-buffer-local'.  The latter function would make
  827.      the variable local to every buffer in which it is subsequently
  828.      set, which would affect buffers that do not use this mode.  It
  829.      is undesirable for a mode to have such global effects.  *Note
  830.      Buffer-Local Variables::.
  831.  
  832.    * If hooks are appropriate for the mode, the major mode command
  833.      should run the hooks after completing all other initialization
  834.      so the user may further customize any of the settings.  *Note
  835.      Hooks::.
  836.  
  837.    * If this mode is appropriate only for specially-prepared text,
  838.      then the major mode command symbol should have a property named
  839.      `mode-class' with value `special', put on as follows:
  840.  
  841.           (put 'funny-mode 'mode-class 'special)
  842.  
  843.      This tells Emacs that new buffers created while the current
  844.      buffer has Funny mode should not inherit Funny mode.  Modes such
  845.      as Dired, Rmail, and Buffer List use this feature.
  846.  
  847.    * If it is desirable that Emacs use the new mode by default after
  848.      visiting files with certain recognizable names, add an element
  849.      to `auto-mode-alist' to select the mode for those file names. 
  850.      If you define the mode command to autoload, you should add this
  851.      element at the same time.  Otherwise, it is sufficient to add
  852.      the element in the file that contains the mode definition. 
  853.      *Note Auto Major Mode::.
  854.  
  855.    * In the documentation, you should provide a sample `autoload'
  856.      form and a sample `auto-mode-alist' addition that users can
  857.      include in their `.emacs' files.
  858.  
  859.    * The top level forms in the file defining the mode should be
  860.      written so that they may be evaluated more than once without
  861.      adverse consequences.  Even if you never load the file more than
  862.      once, someone else will.
  863.  
  864.  
  865. 
  866. File: elisp,  Node: Example Major Modes,  Next: Auto Major Mode,  Prev: Major Mode Conventions,  Up: Major Modes
  867.  
  868. Major Mode Examples
  869. -------------------
  870.  
  871.    Text mode is perhaps the simplest mode besides Fundamental mode. 
  872. Here are excerpts from  `text-mode.el' that illustrate many of the
  873. conventions listed above:
  874.  
  875.      ;; Create mode-specific tables.
  876.      (defvar text-mode-syntax-table nil 
  877.        "Syntax table used while in text mode.")
  878.      
  879.      (if text-mode-syntax-table
  880.          ()              ; Do not change the table if it is already set up.
  881.        (setq text-mode-syntax-table (make-syntax-table))
  882.        (set-syntax-table text-mode-syntax-table)
  883.        (modify-syntax-entry ?\" ".   " text-mode-syntax-table)
  884.        (modify-syntax-entry ?\\ ".   " text-mode-syntax-table)
  885.        (modify-syntax-entry ?' "w   " text-mode-syntax-table))
  886.      
  887.      (defvar text-mode-abbrev-table nil
  888.        "Abbrev table used while in text mode.")
  889.      (define-abbrev-table 'text-mode-abbrev-table ())
  890.      
  891.      (defvar text-mode-map nil "")   ; Create a mode-specific keymap.
  892.      
  893.      (if text-mode-map
  894.          ()              ; Do not change the keymap if it is already set up.
  895.        (setq text-mode-map (make-sparse-keymap))
  896.        (define-key text-mode-map "\t" 'tab-to-tab-stop)
  897.        (define-key text-mode-map "\es" 'center-line)
  898.        (define-key text-mode-map "\eS" 'center-paragraph))
  899.  
  900.    Here is the complete major mode function definition for Text mode:
  901.  
  902.      (defun text-mode ()
  903.        "Major mode for editing text intended for humans to read. 
  904.       Special commands: \\{text-mode-map}
  905.      Turning on text-mode calls the value of the variable text-mode-hook,
  906.      if that value is non-nil."
  907.        (interactive)
  908.        (kill-all-local-variables)
  909.        (use-local-map text-mode-map)     ; This provides the local keymap.
  910.        (setq mode-name "Text")           ; This name goes into the mode line.
  911.        (setq major-mode 'text-mode)      ; This is how `describe-mode'
  912.                                          ;     finds the doc string to print.
  913.        (setq local-abbrev-table text-mode-abbrev-table)
  914.        (set-syntax-table text-mode-syntax-table)
  915.        (run-hooks 'text-mode-hook))      ; Finally, this permits the user to
  916.                                          ;     customize the mode with a hook.
  917.  
  918.     The three Lisp modes (Lisp mode, Emacs Lisp mode, and Lisp
  919. Interaction mode) have more features than Text mode and the code is
  920. correspondingly more complicated.  Here are excerpts from
  921. `lisp-mode.el' that illustrate how these modes are written.
  922.  
  923.      ;; Create mode-specific table variables.
  924.      (defvar lisp-mode-syntax-table nil "")  
  925.      (defvar emacs-lisp-mode-syntax-table nil "")
  926.      (defvar lisp-mode-abbrev-table nil "")
  927.      
  928.      (if (not emacs-lisp-mode-syntax-table) ; Do not change the table
  929.                                             ; if it is already set.
  930.          (let ((i 0))
  931.            (setq emacs-lisp-mode-syntax-table (make-syntax-table))
  932.      
  933.            ;; Set syntax of chars up to 0 to class of chars that are
  934.            ;; part of symbol names but not words.
  935.            ;; (The number 0 is `48' in the ASCII character set.)
  936.            (while (< i ?0) 
  937.              (modify-syntax-entry i "_   " emacs-lisp-mode-syntax-table)
  938.              (setq i (1+ i)))
  939.            ...
  940.            ;; Set the syntax for other characters.
  941.            (modify-syntax-entry ?  "    " emacs-lisp-mode-syntax-table)
  942.            (modify-syntax-entry ?\t "    " emacs-lisp-mode-syntax-table)
  943.            ...
  944.            (modify-syntax-entry ?\( "()  " emacs-lisp-mode-syntax-table)
  945.            (modify-syntax-entry ?\) ")(  " emacs-lisp-mode-syntax-table)
  946.            ...))
  947.      ;; Create an abbrev table for lisp-mode.
  948.      (define-abbrev-table 'lisp-mode-abbrev-table ())
  949.  
  950.    Much code is shared among the three Lisp modes; the code is all in
  951. one library.  The following function sets various variables; it is
  952. called by each of the major Lisp mode functions:
  953.  
  954.      (defun lisp-mode-variables (lisp-syntax)
  955.        ;; The `lisp-syntax' argument is `nil' in Emacs Lisp mode,
  956.        ;; and `t' in the other two Lisp modes.
  957.        (cond (lisp-syntax
  958.               (if (not lisp-mode-syntax-table)
  959.                   ;; The Emacs Lisp mode syntax table always exists, but
  960.                   ;; the Lisp Mode syntax table is created the first time a
  961.                   ;; mode that needs it is called.  This is to save space.
  962.                   (progn (setq lisp-mode-syntax-table
  963.                             (copy-syntax-table emacs-lisp-mode-syntax-table))
  964.                          ;; Change some entries for Lisp mode.
  965.                          (modify-syntax-entry ?\| "\"   "
  966.                                               lisp-mode-syntax-table)
  967.                          (modify-syntax-entry ?\[ "_   "
  968.                                               lisp-mode-syntax-table)
  969.                          (modify-syntax-entry ?\] "_   "
  970.                                               lisp-mode-syntax-table)))
  971.  
  972.         (set-syntax-table lisp-mode-syntax-table)))
  973.        (setq local-abbrev-table lisp-mode-abbrev-table)
  974.        ...)
  975.  
  976.    Functions such as `forward-word' use the value of the
  977. `paragraph-start' variable.  Since Lisp code is different from
  978. ordinary text, the `paragraph-start' variable needs to be set
  979. specially to handle Lisp.  Also, comments are indented in a special
  980. fashion in Lisp and the Lisp modes need their own mode-specific
  981. `comment-indent-hook'.  The code to set these variables is the rest
  982. of `lisp-mode-variables'.
  983.  
  984.        (make-local-variable 'paragraph-start)
  985.        (setq paragraph-start (concat "^$\\|" page-delimiter))
  986.        ...
  987.        (make-local-variable 'comment-indent-hook)
  988.        (setq comment-indent-hook 'lisp-comment-indent))
  989.  
  990.    Each of the different Lisp modes has a slightly different keymap. 
  991. For example, Lisp mode binds `C-c C-l' to `run-lisp', but the other
  992. Lisp modes do not.  However, all Lisp modes have some commands in
  993. common.  The following function adds these common commands to a given
  994. keymap.
  995.  
  996.      (defun lisp-mode-commands (map)
  997.        (define-key map "\e\C-q" 'indent-sexp)
  998.        (define-key map "\177" 'backward-delete-char-untabify)
  999.        (define-key map "\t" 'lisp-indent-line))
  1000.  
  1001.    Here is an example of using `lisp-mode-commands' to initialize a
  1002. keymap, as part of the code for Emacs Lisp mode.  First `defvar' is
  1003. used to declare a mode-specific keymap variable.  Then `boundp' tests
  1004. whether the `emacs-lisp-mode-map' variable has a value (is not void).
  1005. If the variable does have a value, we do not change it.  This lets
  1006. the user customize the keymap if he or she so wishes.  Otherwise, we
  1007. initialize it to a new sparse keymap and install the default key
  1008. bindings.
  1009.  
  1010.      (defvar emacs-lisp-mode-map () "") 
  1011.      
  1012.      (if emacs-lisp-mode-map
  1013.          ()
  1014.        (setq emacs-lisp-mode-map (make-sparse-keymap))
  1015.        (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)
  1016.        (lisp-mode-commands emacs-lisp-mode-map))
  1017.  
  1018.    Finally, here is the complete major mode function definition for
  1019. Emacs Lisp mode.
  1020.  
  1021.      (defun emacs-lisp-mode ()
  1022.        "Major mode for editing Lisp code to run in Emacs.
  1023.      Commands:
  1024.      Delete converts tabs to spaces as it moves back.
  1025.      Blank lines separate paragraphs.  Semicolons start comments.
  1026.      \\{emacs-lisp-mode-map}
  1027.      Entry to this mode calls the value of emacs-lisp-mode-hook
  1028.      if that value is non-nil."
  1029.        (interactive)
  1030.        (kill-all-local-variables)
  1031.        (use-local-map emacs-lisp-mode-map)    ; This provides the local keymap.
  1032.        (set-syntax-table emacs-lisp-mode-syntax-table)
  1033.        (setq major-mode 'emacs-lisp-mode)     ; This is how `describe-mode'
  1034.                                               ;   finds out what to describe.
  1035.        (setq mode-name "Emacs-Lisp")          ; This goes into the mode line.
  1036.        (lisp-mode-variables nil)              ; This define various variables.
  1037.        (run-hooks 'emacs-lisp-mode-hook))     ; This permits the user to use a
  1038.                                               ;   hook to customize the mode.
  1039.  
  1040.  
  1041. 
  1042. File: elisp,  Node: Auto Major Mode,  Next: Mode Help,  Prev: Example Major Modes,  Up: Major Modes
  1043.  
  1044. How Emacs Chooses a Major Mode Automatically
  1045. --------------------------------------------
  1046.  
  1047.    Based on information in the file name or in the file itself, Emacs
  1048. automatically selects a major mode for the new buffer when a file is
  1049. visited.
  1050.  
  1051.  * Command: fundamental-mode
  1052.      Fundamental mode is a major mode that is not specialized for
  1053.      anything in particular.  Other major modes are defined in effect
  1054.      by comparison with this one--their definitions say what to
  1055.      change, starting from Fundamental mode.  The `fundamental-mode'
  1056.      function does *not* run any hooks, so it is not readily
  1057.      customizable.
  1058.  
  1059.  * Command: normal-mode &optional FIND-FILE
  1060.      This function establishes the proper major mode and local
  1061.      variable bindings for the current buffer.  First it calls
  1062.      `set-auto-mode', then it runs `hack-local-variables' to parse,
  1063.      and bind or evaluate as appropriate, any local variables.
  1064.  
  1065.      If the FIND-FILE argument to `normal-mode' is non-`nil',
  1066.      `normal-mode' assumes that the `find-file' function is calling
  1067.      it.  In this case, if `inhibit-local-variables' is non-`nil', it
  1068.      asks for confirmation before processing a local variables list. 
  1069.      If you run `normal-mode' yourself, the argument FIND-FILE is
  1070.      normally `nil', so confirmation is not requested.
  1071.  
  1072.      `normal-mode' uses `condition-case' around the call to the major
  1073.      mode function, so errors are caught and reported as a `File mode
  1074.      specification error',  followed by the original error message.
  1075.  
  1076.  * Function: set-auto-mode
  1077.      This function selects the major mode that is appropriate for the
  1078.      current buffer.  It may base its decision on the value of the
  1079.      `-*-' line, on the visited file name (using `auto-mode-alist'),
  1080.      or on the value of a local variable).  However, this function
  1081.      does not look for the `mode:' local variable near the end of a
  1082.      file; the `hack-local-variables' function does that.  *Note :
  1083.      (emacs)Choosing Modes.
  1084.  
  1085.  * User Option: default-major-mode
  1086.      This variable holds the default major mode for new buffers.  The
  1087.      standard value is `fundamental-mode'.
  1088.  
  1089.      If the value of `default-major-mode' is `nil', Emacs uses the
  1090.      (previously) current buffer's major mode for major mode of a new
  1091.      buffer.  However, if the major mode symbol has a `mode-class'
  1092.      property with value `special', then it is not used for new
  1093.      buffers; Fundamental mode is used instead.  The modes that have
  1094.      this property are those such as Dired and Rmail that are useful
  1095.      only with text that has been specially prepared.
  1096.  
  1097.  * Variable: initial-major-mode
  1098.      The value of this variable determines the major mode of the
  1099.      initial `*scratch*' buffer.  The value should be a symbol that
  1100.      is a major mode command name.  The default value is
  1101.      `lisp-interaction-mode'.
  1102.  
  1103.  * Variable: auto-mode-alist
  1104.      This variable contains an association list of file name patterns
  1105.      (regular expressions; *note Regular Expressions::.) and
  1106.      corresponding major mode functions.  Usually, the file name
  1107.      patterns test for suffixes, such as `.el' and `.c', but this
  1108.      need not be the case.  Each element of the alist looks like
  1109.      `(REGEXP .  MODE-FUNCTION)'.
  1110.  
  1111.      For example,
  1112.  
  1113.           (("^/tmp/fol/" . text-mode)
  1114.            ("\\.texinfo$" . texinfo-mode)
  1115.            ("\\.texi$" . texinfo-mode)
  1116.            ("\\.el$" . emacs-lisp-mode)
  1117.            ("\\.c$" . c-mode) 
  1118.            ("\\.h$" . c-mode)
  1119.            ...)
  1120.  
  1121.      When you visit a file whose *full* path name matches a REGEXP,
  1122.      `set-auto-mode' calls the corresponding MODE-FUNCTION.  This
  1123.      feature enables Emacs to select the proper major mode for most
  1124.      files.
  1125.  
  1126.      Here is an example of how to prepend several pattern pairs to an
  1127.      existing `auto-mode-alist'.  (You might use this sort of
  1128.      expression in your `.emacs' file.)
  1129.  
  1130.           (setq auto-mode-alist
  1131.             (append 
  1132.              '(("/\\.[^/]*$" . fundamental-mode)  ; Filename starts with a dot.
  1133.                ("[^\\./]*$" . fundamental-mode)   ; Filename has no dot.
  1134.                ("\\.C$" . c++-mode))
  1135.              auto-mode-alist))
  1136.  
  1137.  * Function: hack-local-variables &optional FORCE
  1138.      This function parses, and binds or evaluates as appropriate, any
  1139.      local variables for the current buffer.
  1140.  
  1141.      If the variable `inhibit-local-variables' is non-`nil', and
  1142.      FORCE is `nil', then the user is asked for confirmation if the
  1143.      buffer does contain local variable specifications.  A non-`nil'
  1144.      value of FORCE is passed by `normal-mode' when it is called
  1145.      explicitly by the user.
  1146.  
  1147.      *Note : (emacs)File variables, for the syntax of the local
  1148.      variables section of a file.
  1149.  
  1150.  * User Option: inhibit-local-variables
  1151.      When this variable is non-`nil', `hack-local-variables' asks the
  1152.      user for confirmation before obeying a file's local-variables
  1153.      list.
  1154.  
  1155.  
  1156. 
  1157. File: elisp,  Node: Mode Help,  Prev: Auto Major Mode,  Up: Major Modes
  1158.  
  1159. Getting Help about a Major Mode
  1160. -------------------------------
  1161.  
  1162.    The `describe-mode' function is used to provide information about
  1163. major modes.  It is normally called with `C-h m'.  The
  1164. `describe-mode' function uses the value of `major-mode', which is why
  1165. every major mode function needs to set the `major-mode' variable.
  1166.  
  1167.  * Command: describe-mode
  1168.      This function displays the documentation of the current major
  1169.      mode.
  1170.  
  1171.      The `describe-mode' function calls the `documentation' function
  1172.      using the value of `major-mode' as an argument.  Thus, it
  1173.      displays the documentation string of the major mode function. 
  1174.      (*Note Accessing Documentation::.)
  1175.  
  1176.  * Variable: major-mode
  1177.      This variable holds the symbol for the current buffer's major
  1178.      mode.  This symbol should be the name of the function that is
  1179.      called to initialize the mode.  The `describe-mode' function
  1180.      uses the documentation string of this symbol as the
  1181.      documentation of the major mode.
  1182.  
  1183.  
  1184.